<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;}
#l-map{height:100%;width:78%;float:left;border-right:2px solid #bcbcbc;}
#r-result{height:100%;width:20%;float:left;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=1.3"></script>
<script type="text/javascript" src="http://dev.baidu.com/wiki/static/map/API/examples/script/convertor.js"></script>
<title>地图</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
var map;
function setMap(lng, lat) {
	map = new BMap.Map("allmap");
    var gpsPoint = new BMap.Point(121.54, 38.88);
    setTimeout(function(){
    BMap.Convertor.translate(gpsPoint,0,translateCallback);     //真实经纬度转成百度坐标
}, 2000);
    
}
// 编写自定义函数,创建标注
function addMarker(lng, lat, type){
  var point = new BMap.Point(lng, lat);
  var marker = new BMap.Marker(point);
  var myIcon;
  var tp = type;
  if (tp == "0") {
  	myIcon = new BMap.Icon("red.png", new BMap.Size(22, 29), {offset: new BMap.Size(10, 29),imageOffset: new BMap.Size(0, 0)});    
  } else {
    myIcon = new BMap.Icon("green.png", new BMap.Size(22, 29), {offset: new BMap.Size(10, 29),imageOffset: new BMap.Size(0, 0)});    
  }  
 
  marker.setIcon(myIcon);
  map.addOverlay(marker);
}


//坐标转换完之后的回调函数
translateCallback = function (point){
   map.centerAndZoom(point, 10);
   addMarker(point.lng, point.lat, type)
   map.addControl(new BMap.NavigationControl({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, type: BMAP_NAVIGATION_CONTROL_ZOOM}));  //右下角，仅包含缩放按钮
}



function addMulPoint() {

// 随机向地图添加25个标注
var bounds = map.getBounds();
var sw = bounds.getSouthWest();
var ne = bounds.getNorthEast();
var lngSpan = Math.abs(sw.lng - ne.lng);
var latSpan = Math.abs(ne.lat - sw.lat);
for (var i = 0; i < 25; i ++) {
if (i > 10) {
addMarker(sw.lng + lngSpan * (Math.random() * 0.7), ne.lat - latSpan * (Math.random() * 0.7), "0");
} else {
addMarker(sw.lng + lngSpan * (Math.random() * 0.7), ne.lat - latSpan * (Math.random() * 0.7), "1");
}
}
}


</script>